package homework;

import java.io.*;

public class Test2 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //获得当前目录下的所有子项
        File dir = new File(".");
        //利用筛选器查找子项中所有后缀为.obj的子项
        File[] subs = dir.listFiles(f->f.getName().endsWith(".obj"));
        //遍历所有.obj
        for (int i = 0; i <subs.length ; i++) {
            //获得每一个obj文件
            File sub = subs[i];
            //定义文件输入流fis
            FileInputStream fis = new FileInputStream(sub);
            //对象输入流ois
            ObjectInputStream ois = new ObjectInputStream(fis);
            //获取的对象序列化
            Object obj = ois.readObject();
            //判断obj对象是否属于User类型
            if(obj instanceof User){
                //把obj强转为User类型
                User user = (User)obj;
                //输出user
                System.out.println(user);
            }
        }

    }
}
